﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <WtmSearcher v-model="searchDataCollectTask" @search="()=>{getTableDataCollectTask();}">
      <el-row>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="TaskName_FormItem" prop="TaskName" :label="$t('message.autotrans._Model_CollectTask_TaskName')">
            <el-input v-model="searchDataCollectTask.TaskName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="TargetDeviceType_FormItem" prop="TargetDeviceType" :label="$t('message.autotrans._Model_CollectTask_TargetDeviceType')">
            <el-select v-model="searchDataCollectTask.TargetDeviceType" clearable>
               <el-option key="ElectricMeter" value="ElectricMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_ElectricMeter')"></el-option>
               <el-option key="PressureMeter" value="PressureMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_PressureMeter')"></el-option>
               <el-option key="FlowMeter" value="FlowMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_FlowMeter')"></el-option>
               <el-option key="ProtectiveGasMeter" value="ProtectiveGasMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_ProtectiveGasMeter')"></el-option>
               <el-option key="GasMeter" value="GasMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_GasMeter')"></el-option>
               <el-option key="WaterMeter" value="WaterMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_WaterMeter')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="DeviceId_FormItem" prop="DeviceId" :label="$t('message.autotrans._Model_CollectTask_Device')">
            <el-select v-model="searchDataCollectTask.DeviceId" clearable>
               <el-option v-for="item in stateCollectTask.AllDevices" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="IntervalMinutes_FormItem" prop="IntervalMinutes" :label="$t('message.autotrans._Model_CollectTask_IntervalMinutes')">
            <el-input v-model="searchDataCollectTask.IntervalMinutes" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="StartTime_FormItem" prop="StartTime" :label="$t('message.autotrans._Model_CollectTask_StartTime')">
            <el-date-picker v-model="searchDataCollectTask.StartTime" type='daterange' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="EndTime_FormItem" prop="EndTime" :label="$t('message.autotrans._Model_CollectTask_EndTime')">
            <el-date-picker v-model="searchDataCollectTask.EndTime" type='daterange' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="Status_FormItem" prop="Status" :label="$t('message.autotrans._Model_CollectTask_Status')">
            <el-select v-model="searchDataCollectTask.Status" clearable>
               <el-option key="Enabled" value="Enabled" :label="$t('message.autotrans._Enum_TaskStatusEnum_Enabled')"></el-option>
               <el-option key="Paused" value="Paused" :label="$t('message.autotrans._Enum_TaskStatusEnum_Paused')"></el-option>
               <el-option key="Completed" value="Completed" :label="$t('message.autotrans._Enum_TaskStatusEnum_Completed')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="CreateTime_FormItem" prop="CreateTime" :label="$t('message.autotrans._Model_CollectTask_CreateTime')">
            <el-date-picker v-model="searchDataCollectTask.CreateTime" type='daterange' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="UpdateTime_FormItem" prop="UpdateTime" :label="$t('message.autotrans._Model_CollectTask_UpdateTime')">
            <el-date-picker v-model="searchDataCollectTask.UpdateTime" type='daterange' clearable></el-date-picker>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="CreateBy_FormItem" prop="CreateBy" :label="$t('message.autotrans._Model_CollectTask_CreateBy')">
            <el-input v-model="searchDataCollectTask.CreateBy" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="UpdateBy_FormItem" prop="UpdateBy" :label="$t('message.autotrans._Model_CollectTask_UpdateBy')">
            <el-input v-model="searchDataCollectTask.UpdateBy" clearable></el-input>
        </el-form-item>

        </el-col>
      </el-row>

  </WtmSearcher>

  <div style="text-align: right;">
      <WtmButton v-auth="'/api/IoTManagement/CollectTask/Create'" icon='fa fa-plus' type='primary' :button-text="$t('message.autotrans.SysCreate')" @click="OnCreateClick()"/>
    <WtmButton v-auth="'/api/IoTManagement/CollectTask/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message.autotrans.SysDelete')" :confirm="$t('message._system.common.vm.deletetip')" @click="onBatchDelete()"/>
    <WtmButton v-auth="'/api/IoTManagement/CollectTask/BatchEdit'" icon='fa fa-pencil-square' type='primary' :button-text="$t('message.autotrans.SysBatchEdit')" @click="OnBatchEditClick()"/>
    <WtmButton v-auth="'/api/IoTManagement/CollectTask/Import'" icon='fa fa-tasks' type='primary' :button-text="$t('message.autotrans.SysImport')" @click="OnImportClick()"/>
    <WtmButton v-auth="'/api/IoTManagement/CollectTask/CollectTaskExportExcel'"  icon='fa fa-arrow-circle-down' type='primary' :button-text="$t('message.autotrans.SysExport')" @click="onExport()"/>

  </div>
  <WtmTable ref="tableRefCollectTask" v-bind="tableDataCollectTask">
    <template #operation>
      <el-table-column :label="$t('message._system.common.vm.operate')" width="180">
        <template v-slot="scope">
            <WtmButton v-auth="'/api/IoTManagement/CollectTask/Edit'" :is-text="true" icon='fa fa-pencil-square' type='warning' :button-text="$t('message.autotrans.SysEdit')" @click="OnEditrowClick(scope.row)"/>
          <WtmButton v-auth="'/api/IoTManagement/CollectTask/{id}'" :is-text="true" icon='fa fa-info-circle' type='info' :button-text="$t('message.autotrans.Page详情')" @click="OnDetailsrowClick(scope.row)"/>
          <WtmButton v-auth="'/api/IoTManagement/CollectTask/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message.autotrans.SysDelete')" :confirm="$t('message._system.common.vm.deletetip')" :is-text="true"  @click="onDelete(scope.row)"/>

        </template>
      </el-table-column>
    </template>
  </WtmTable>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageIoTManagementCollectTaskIndex;true;Digitalmes.IoTManagement.Controllers;CollectTask">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { collecttaskApi } from '/@/api/iotmanagement/collecttask';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;

const CreateDialog = defineAsyncComponent(() => import('./create.vue'));
const EditDialog = defineAsyncComponent(() => import('./edit.vue'));
const DetailsDialog = defineAsyncComponent(() => import('./details.vue'));
const BatchEditDialog = defineAsyncComponent(() => import('./batchedit.vue'));
const ImportDialog = defineAsyncComponent(() => import('./import.vue'));

const stateCollectTask = reactive({
    
    AllDevices: [] as any[],
});

const searchDataCollectTask = ref({
        TaskName: '',
        TargetDeviceType: undefined,
        DeviceId: null,
        IntervalMinutes: null,
        StartTime: undefined,
        EndTime: undefined,
        Status: undefined,
        CreateTime: undefined,
        UpdateTime: undefined,
        CreateBy: '',
        UpdateBy: '',
});

// 定义变量内容
const tableRefCollectTask = ref();
const tableDataCollectTask = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
      {title:ci.proxy.$t('message.autotrans.Page任务名称'),key: 'CollectTask_TaskName',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page设备类型'),key: 'CollectTask_TargetDeviceType',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page设备'),key: 'CollectTask_Device',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page采集频率'),key: 'CollectTask_IntervalMinutes',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page开始时间'),key: 'CollectTask_StartTime',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page结束时间'),key: 'CollectTask_EndTime',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page任务状态'),key: 'CollectTask_Status',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminCreateTime'),key: 'CollectTask_CreateTime',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminUpdateTime'),key: 'CollectTask_UpdateTime',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminCreateBy'),key: 'CollectTask_CreateBy',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans._AdminUpdateBy'),key: 'CollectTask_UpdateBy',type: 'text',isCheck: true},

	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: true, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
	}
});
// 初始化表格数据
const getTableDataCollectTask = () => {
    tableRefCollectTask.value.doSearch(collecttaskApi().search, searchDataCollectTask.value)
        .catch((error: any) => {
			other.setFormError(ci, error);
		});
};
const OnCreateClick = () => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysCreate'), CreateDialog, null, getTableDataCollectTask)
};

const OnEditrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysEdit'), EditDialog, row, getTableDataCollectTask)
};

const OnDetailsrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message.autotrans.Page详情'), DetailsDialog, row, getTableDataCollectTask)
};

// 删除
const onDelete = (row: any) => {
    collecttaskApi().delete([row.ID]).then(() => { getTableDataCollectTask()})
};

const onBatchDelete = () => {
    const selectedrows = tableRefCollectTask.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      collecttaskApi().delete(selectedids).then(() => { getTableDataCollectTask()})
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnBatchEditClick = () => {
    const selectedrows = tableRefCollectTask.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      other.openDialog(ci.proxy.$t('message.autotrans.SysBatchEdit'), BatchEditDialog, selectedids, getTableDataCollectTask)
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnImportClick = () => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysImport'), ImportDialog, null, getTableDataCollectTask)
};

const onExport = () => {
	const selected = tableRefCollectTask.value.getSelectedRows();
	if (selected.length > 0) {
		collecttaskApi().exportById(selected.map((x: any) => x.ID));
	}
	else {
		collecttaskApi().export({});
	}
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/IoTManagement/CollectTask/GetMeterDevices',[],false).then(x=>{stateCollectTask.AllDevices = x});
        getTableDataCollectTask();

});

// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

